<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php

//********** online_crm encrypt  
if (!isset($_GET['time']) || !isset($_GET['token']))
	return;

// Verify token first
$privateKey = 'PRIVATEKEY';
$time = $_GET['time'];
$token = $_GET['token'];
$token2 = hash_hmac('sha256', $time, $privateKey);
if ($token != $token2) {
	return;
}

// Check timespan
if (abs(time() - $time) > 5)
	return;
//**********


ini_set('html_errors',true); 
ini_set('display_errors',true);
include("function.inc");
$mysql_server_name = "localhost";
$mysql_username = "Morgansecrm";
$mysql_password = "morgansecrm";
$mysql_database = "morganse_crm";
$conn=mysql_connect($mysql_server_name, $mysql_username, $mysql_password);
mysql_select_db($mysql_database);
$id = $_GET["id"];

// by date
$strsql = "select * from app_info where app_id =".$id; 
//echo $strsql;
$rs = mysql_query($strsql) or die("Query failed");
$arrayres = mysql_fetch_assoc($rs);


?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo "#".$arrayres["app_Surname1"]." ".$arrayres["app_FirstName1"]." $".$arrayres["app_LoanAmount"]; ?> Application Form</title>
</head>

<body>
<?php
/*if(empty($arrayres["app_referrerName"]) && empty($arrayres["app_businessStage"]) && $arrayres["app_PurposeSummary"]=="Personal")
 		// all in one form personal purpose
	$strEMailTemplate = "application_resend_new.html";
else if(empty($arrayres["app_referrerName"]) && $arrayres["app_PurposeSummary"]=="Business") 			// business form
	$strEMailTemplate = "application_resend2_new.html";
else if(($arrayres["app_Residency"])=="-Select-"	)											// broker business form
    $strEMailTemplate = "application_resend3.html";
else																// broker personal form
	$strEMailTemplate = "application_resend4.html";	
if(	$arrayres["app_referrerName"]!="" && $arrayres["app_whoComplete"]=="" && $arrayres["app_PurposeSummary"]=="Personal")
	$strEMailTemplate = "application_resend_new.html";
if(	$arrayres["app_referrerName"]!="" && $arrayres["app_whoComplete"]=="" && $arrayres["app_PurposeSummary"]=="Business")
	$strEMailTemplate = "application_resend2_new.html";
if( $arrayres["app_GeneralForm"]=="Yes" &&  $arrayres["app_referrerName"]=="")
	$strEMailTemplate = "general_form_db_view.html";
if( $arrayres["app_GeneralForm"]=="Yes" &&  $arrayres["app_referrerName"]=="" && $arrayres["app_PurposeSummary"]=="Business" && $arrayres["app_NumberofDependant1"]=="")
	$strEMailTemplate = "business_form_db_view.html";*/
	
/*if( $arrayres["app_NumberofDependant1"]!="" )
	$strEMailTemplate = "general_form_db_view.html";
else 
	$strEMailTemplate = "business_form_db_view.html";	*/
	
if( $arrayres["app_PurposeSummary"]=='Personal' )
	$strEMailTemplate = "general_form_db_view_print.html";
else 
	$strEMailTemplate = "business_form_db_view_print.html";	

$strEMailContent='';
	$filHandle = fopen("email/". $strEMailTemplate, "r");
	while ($strLine = fgets($filHandle, 1000))
        $strEMailContent .= $strLine;
	fclose($filHandle);

$ict_view="none";

foreach ($arrayres as $strKey => $strValue){
	   	$tmpkey = str_replace("app_","",$strKey);

//format all money values 
		if (is_num(trim($strValue))&&trim($strValue).substr(0,1)!="0"&&(strpos(("fix,Fax1,Fax2,WorkPhone1,WorkPhone2,Postcode1,Postcode2,DriversLicence1,DriversLicence2,Mobile1,Mobile2,Phone1,Phone2,Motor1Year,Motor2Year,ContactNumber1,ContactNumber2,AbnNumber1,AbnNumber2,YearEstablished1,YearEstablished2,Property1Postcode,Property2Postcode"),trim($tmpkey))==false))
			$strValue = formatMoney($strValue);

//three key points display
		if ($tmpkey=="RemIncomeTotal" && $strValue<0)
			$ict_view="";
		
		if (($tmpkey=="Motor1Finance"&&$strValue=="Yes")||($tmpkey=="Motor2Finance"&&$strValue=="Yes")||($tmpkey=="morarr1"&&$strValue=="yes")||($tmpkey=="morarr2"&&$strValue=="yes"))
			$strValue= $strValue.' <img src="../Pics/stars_grey.png" width="20" height="18" border="0">';

		if ($strValue=="-Select-")
			$strValue="";
		$strEMailContent = str_ireplace("{\$" . $tmpkey . "}", $strValue, $strEMailContent);
}	

//echo $arrayres["app_businessStage"];
//$strEMailContent = str_ireplace("{\$businessStage}", $arrayres["app_businessStage"], $strEMailContent);
//$strEMailContent = str_ireplace("{\$entityType}", $arrayres["app_entityType"], $strEMailContent);

$strEMailContent = str_ireplace("{\$ict_view}", $ict_view, $strEMailContent);

//change date/time format
$tmpdate = strtotime($arrayres["app_Date"]);
$Date = date("d M Y",$tmpdate);

$tmptime = strtotime($arrayres["app_Time"]);
$Time = date("h:i a",$tmptime);


$strEMailContent = str_ireplace("{\$submittedDate}", $Date, $strEMailContent);

$strEMailContent = str_ireplace("{\$submittedTime}", $Time, $strEMailContent);		
//determine purpose 
$PurposeSummary='';
	
	if ($arrayres["app_PurposeOfLoan1"]=="Personal bills/Vehicle Registration"||$arrayres["app_PurposeOfLoan1"]=="Personal purchases"||$arrayres["app_PurposeOfLoan1"]=="Rental bond"||$arrayres["app_PurposeOfLoan1"]=="Investment/Share purchase in personal name"||$arrayres["app_PurposeOfLoan1"]=="Residential property renovation"||$arrayres["app_PurposeOfLoan1"]=="Residential property use"||$arrayres["app_PurposeOfLoan1"]=="Holiday/Wedding"||$arrayres["app_PurposeOfLoan1"]=="Other personal use"){
		$PurposeSummary = "Personal";
	}
	if ($arrayres["app_PurposeOfLoan1"]=="Business operating cash flow"||$arrayres["app_PurposeOfLoan1"]=="Startup a new business"||$arrayres["app_PurposeOfLoan1"]=="Renew business vehicle Registration"||$arrayres["app_PurposeOfLoan1"]=="Pay business bills/debt"||$arrayres["app_PurposeOfLoan1"]=="Buy business equipment"||$arrayres["app_PurposeOfLoan1"]=="Buy business stock"||$arrayres["app_PurposeOfLoan1"]=="Capital injection into company"||$arrayres["app_PurposeOfLoan1"]=="Commercial property use"||$arrayres["app_PurposeOfLoan1"]=="Commercial property renovation"||$arrayres["app_PurposeOfLoan1"]=="Purchase shares using company/trust"||$arrayres["app_PurposeOfLoan1"]=="Purchase currency using company/trust"||$arrayres["app_PurposeOfLoan1"]=="Other business use"){
		$PurposeSummary = "Business";
	}

$CalDisplay = "none";
$hardshipdisplay = "none";
$gamblingdisplay = "none";

	if ($PurposeSummary=="Personal"){
		$hardshipdisplay = "";
		$CalDisplay = "";
		$gamblingdisplay = "";
	}
	else{ 
		$CalDisplay = "none";
		$hardshipdisplay = "none";
		$gamblingdisplay = "none";
	}
	
	
	
$strEMailContent = str_ireplace("{\$PurposeSummary}", $PurposeSummary, $strEMailContent);	
	
$strEMailContent = str_ireplace("{\$CalDisplay}", $CalDisplay, $strEMailContent);

$strEMailContent = str_ireplace("{\$hardshipdisplay}", $hardshipdisplay, $strEMailContent);	

$strEMailContent = str_ireplace("{\$gamblingdisplay}", $gamblingdisplay, $strEMailContent);	

if ($arrayres["app_Filledform"]=="No"||$arrayres["app_Filledform"]==""){
	$firstapp_view= "none";
}
else 
	$firstapp_view= "";
$strEMailContent = str_ireplace("{\$firstapp_view}", $firstapp_view, $strEMailContent);	

if ($arrayres["app_ApplicantName"]==""){
	$firstappname = "display:none";
}
else 
	$firstappname= "background-color:#FFFF00";
$strEMailContent = str_ireplace("{\$firstappname}", $firstappname, $strEMailContent);

if ($arrayres["app_ExistingClient"]=="No"){
	$ec_view= "none";
}
else 
	$ec_view= "";
$strEMailContent = str_ireplace("{\$ec_view}", $ec_view, $strEMailContent);	

$TOE1="-Select-";
$TOE2="-Select-";
if (trim($arrayres["app_TOE1"])=="-Select-")
	$TOE1= "";
else 
	$TOE1=$arrayres["app_TOE1"];

if (trim($arrayres["app_TOE2"])=="-Select-")
	$TOE2= "";
else
	$TOE2=$arrayres["app_TOE2"];

$strEMailContent = str_ireplace("{\$aTOE1}",$TOE1,$strEMailContent);
$strEMailContent = str_ireplace("{\$aTOE2}",$TOE2,$strEMailContent);	

$BE_view= "";
if ($arrayres["app_BusinessName1"]==""&&$arrayres["app_BusinessName2"]=="")
	$BE_view= "none";

	
$strEMailContent = str_ireplace("{\$BE_view}", $BE_view, $strEMailContent);	

$addr_view= "";
if ($arrayres["app_Address1"]==""&&$arrayres["app_Address2"]=="")
	$addr_view= "none";

	
$strEMailContent = str_ireplace("{\$addr_view}", $addr_view, $strEMailContent);	

$Occ_view= "";
if ((trim($arrayres["app_TypeOfEmployment1"])=="Centrelink"&&trim($arrayres["app_TypeOfEmployment2"])=="Centrelink")||(trim($arrayres["app_TypeOfEmployment1"])=="Centrelink"&&trim($arrayres["app_TypeOfEmployment2"])=="-Select-")){
	if ($arrayres["app_AbnNumber1"]==""&&$arrayres["app_NatureOfBusiness1"]==""&&$arrayres["app_YearEstablished1"]==""&&$arrayres["app_MoneyDetail1"]==""&&$arrayres["app_Fax1"]==""&&$arrayres["app_NameOfDirectors1"]==""&&$arrayres["app_Occupation1"]==""&&$arrayres["app_YearsInOccupation1"]==""&&$arrayres["app_TitleInOccupation1"]==""&&$arrayres["app_ContactPerson1"]==""&&$arrayres["app_PositionOfContact1"]==""&&$arrayres["app_WorkPhone1"]=="")
	$Occ_view= "none";
}
	
$strEMailContent = str_ireplace("{\$Occ_view}", $Occ_view, $strEMailContent);	
	
if ($arrayres["app_RepaymentDetail"]=="-Select-")
	$RepDetail_view= "none";
else 
	$RepDetail_view= "";
$strEMailContent = str_ireplace("{\$RepDetail_view}", $RepDetail_view, $strEMailContent);

if ($arrayres["app_RepaymentDetail2"]=="-Select-")
	$sor_view= "none";
else 
	$sor_view= "";
$strEMailContent = str_ireplace("{\$sor_view}", $sor_view, $strEMailContent);	

 
	//determine credit
	$CreditSummary="";
	$c1=99;$c2=99;
	switch ($arrayres["app_CreditHistory1"]){
		case "Clean (no default)": $c1=1;
		case "1 default": $c1=2;
		case "2 defaults": $c1=3;
		case "3 or more defaults": $c1=4; 
		case "Under bankruptcy": $c1=5;
		case "Ex-bankrupt": $c1=6;
		case "Under Part IX debt agreement": $c1=7; 
		case "Past Part IX debt agreement": $c1=8; 
	}
	switch ($arrayres["app_CreditHistory2"]){
		case "Clean (no default)": $c2=1;
		case "1 default": $c2=2;
		case "2 defaults": $c2=3;
		case "3 or more defaults": $c2=4;
		case "Under bankruptcy": $c2=5;
		case "Ex-bankrupt": $c2=6;
		case "Under Part IX debt agreement": $c2=7; 
		case "Past Part IX debt agreement": $c2=8; 
	}
	if ($c1>$c2)
		$CreditSummary=$arrayres["app_CreditHistory2"];
	else
		$CreditSummary=$arrayres["app_CreditHistory1"];	
	
	$strEMailContent = str_ireplace("{\$CreditSummary}", $CreditSummary, $strEMailContent);		
	
//asset  visible control	
	$strVisibleVehicle = "none";
	$strVisibleProperty = "none";
		
	if ($arrayres['app_ApplyWithSomeoneWhoOwns'] == "Motor Vehicle(s)"){
		$strVisibleVehicle = "";
		
	}
	if ($arrayres['app_ApplyWithSomeoneWhoOwns'] == "Real Estate Property(s)"){
		$strVisibleProperty = "";
		
	}
	if ($arrayres['app_ApplyWithSomeoneWhoOwns'] == "Motor Vehicle(s) and Real Estate Property(s)"){
		$strVisibleVehicle = "";
		$strVisibleProperty = "";
  		
 	}
	
	$strEMailContent = str_ireplace("{\$strVisibleVehicle}", $strVisibleVehicle, $strEMailContent);
	$strEMailContent = str_ireplace("{\$strVisibleProperty}", $strVisibleProperty, $strEMailContent);
	

//income visible control
$NormalContent1Display="none";
$NormalContent2Display="none";
$ExtraContent1Display="none";
$ExtraContent2Display="none";


if ($arrayres["app_TypeOfEmployment1"] == "Self-Employed"||$arrayres["app_TypeOfEmployment1"] == "Company Director"){
		$NormalContent1Display = "none"; 
		$ExtraContent1Display = ""; 
	} else {
		$NormalContent1Display = ""; 
		$ExtraContent1Display = "none"; 
	}

if ($arrayres["app_TypeOfEmployment2"] == "Self-Employed"||$arrayres["app_TypeOfEmployment2"] == "Company Director"){
		$NormalContent2Display = "none"; 
		$ExtraContent2Display = ""; 
	} else {
		$NormalContent2Display = ""; 
		$ExtraContent2Display = "none"; 
	}


$strEMailContent = str_ireplace("{\$NormalContent1Display}", $NormalContent1Display, $strEMailContent);

$strEMailContent = str_ireplace("{\$NormalContent2Display}", 
$NormalContent2Display, $strEMailContent);

$strEMailContent = str_ireplace("{\$ExtraContent1Display}", $ExtraContent1Display, $strEMailContent);

$strEMailContent = str_ireplace("{\$ExtraContent2Display}", $ExtraContent2Display, $strEMailContent);


//credithistory visible control
$default1display="none";
$default2display="none";

if ($arrayres['app_CreditHistory1']=="1 default"||$arrayres['app_CreditHistory2']=="1 default"){
	$default1display="";
}
if ($arrayres['app_CreditHistory1']=="2 defaults"||$arrayres['app_CreditHistory2']=="2 defaults"||$arrayres['app_CreditHistory1']=="3 or more defaults"||$arrayres['app_CreditHistory2']=="3 or more defaults"){
	$default1display="";
	$default2display="";
	
}
	$strEMailContent = str_ireplace("{\$default1display}", $default1display, $strEMailContent);
	$strEMailContent = str_ireplace("{\$default2display}", $default2display, $strEMailContent);
	
	$dod_view="";
	if ($arrayres['app_DateOfDischarge1']=="")
		$dod_view="none";	
	$strEMailContent = str_ireplace("{\$dod_view}", $dod_view, $strEMailContent);
	
	
	$dad_view="";
	if ($arrayres['app_DefaultAfterDischarge1']=="")
		$dad_view="none";	
	$strEMailContent = str_ireplace("{\$dad_view}", $dad_view, $strEMailContent);	
	
	$mia_view="";
	if ($arrayres['app_monarr1']=="-Select-"&&$arrayres['app_monarr2']=="-Select-")
		$mia_view="none";	
	$strEMailContent = str_ireplace("{\$mia_view}", $mia_view, $strEMailContent);
	
	$bcstate_view="";
	if ($arrayres['app_BadCreditSpecify2']=="")
		$bcstate_view="none";	
	$strEMailContent = str_ireplace("{\$bcstate_view}", $bcstate_view, $strEMailContent);
	
	$secapp_view="visible";
	if ($arrayres['app_NumberPeopleApplying']=="One")
		$secapp_view="hidden";	
	$strEMailContent = str_ireplace("{\$secapp_view}", $secapp_view, $strEMailContent);
	
//cope with mutiple properties

 	$pptynum=0;
	$pptynum=$arrayres['app_AoP']-2;
	
	$p34_view="none";
	$p3_view="none";
	$p4_view="none";
	$p5_view="none";
	if ($arrayres['app_AoP']>=3){
		if ($arrayres['app_AoP']>=5)
			$p5_view="";
		$p34_view="";		
		if ($arrayres['app_AoP']>=3)
			$p3_view="";
		if ($arrayres['app_AoP']>=4)
			$p4_view="";	
	}
	$strEMailContent = str_ireplace("{\$p34_view}", $p34_view, $strEMailContent);
	$strEMailContent = str_ireplace("{\$p3_view}", $p3_view, $strEMailContent);
	$strEMailContent = str_ireplace("{\$p4_view}", $p4_view, $strEMailContent);
	$strEMailContent = str_ireplace("{\$p5_view}", $p5_view, $strEMailContent);
	
	$InvestmentValuea = preg_split("[|]",$arrayres['app_InvestmentValue_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"InvestmentValue".($n+3)}=$InvestmentValuea[$n];	
		$pattern = "InvestmentValue".($n+3);
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"InvestmentValue".($n+3)}, $strEMailContent);
	}
	
	$InvestmentAmountOwinga = preg_split("[|]",$arrayres['app_InvestmentAmountOwing_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"InvestmentAmountOwing".($n+3)}=$InvestmentAmountOwinga[$n];	
		$pattern = "InvestmentAmountOwing".($n+3);
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"InvestmentAmountOwing".($n+3)}, $strEMailContent);
	}
	
	$InvestmentPaymenta = preg_split("[|]",$arrayres['app_InvestmentPayment_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"InvestmentPayment".($n+3)}=$InvestmentPaymenta[$n];	
		$pattern = "InvestmentPayment".($n+3);
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"InvestmentPayment".($n+3)}, $strEMailContent);
	}
	
	$InvestmentBanka = preg_split("[|]",$arrayres['app_InvestmentBank_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"InvestmentBank".($n+3)}=$InvestmentBanka[$n];	
		$pattern = "InvestmentBank".($n+3);
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"InvestmentBank".($n+3)}, $strEMailContent);
	}
	
	$InvestmentOwnera = preg_split("[|]",$arrayres['app_InvestmentOwner_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"InvestmentOwner".($n+3)}=$InvestmentOwnera[$n];	
		$pattern = "InvestmentOwner".($n+3);
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"InvestmentOwner".($n+3)}, $strEMailContent);
	}
	
	$PropertyaAddress = preg_split("[|]",$arrayres['app_PropertyAddress_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"Property".($n+3)."Address"}=$PropertyaAddress[$n];	
		$pattern = "Property".($n+3)."Address";
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"Property".($n+3)."Address"}, $strEMailContent);
	}

	$PropertyaState = preg_split("[|]",$arrayres['app_PropertyState_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"Property".($n+3)."State"}=$PropertyaState[$n];	
		$pattern = "Property".($n+3)."State";
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"Property".($n+3)."State"}, $strEMailContent);
	}
	
	$PropertyaPostcode = preg_split("[|]",$arrayres['app_PropertyPostcode_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"Property".($n+3)."Postcode"}=$PropertyaPostcode[$n];	
		$pattern = "Property".($n+3)."Postcode";
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"Property".($n+3)."Postcode"}, $strEMailContent);
	}
	
	$PropertyaDebt1st = preg_split("[|]",$arrayres['app_PropertyDebt1st_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"Property".($n+3)."Debt1st"}=$PropertyaDebt1st[$n];	
		$pattern = "Property".($n+3)."Debt1st";
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"Property".($n+3)."Debt1st"}, $strEMailContent);
	}
	
	$PropertyaDebt2nd = preg_split("[|]",$arrayres['app_PropertyDebt2nd_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"Property".($n+3)."Debt2nd"}=$PropertyaDebt2nd[$n];	
		$pattern = "Property".($n+3)."Debt2nd";
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"Property".($n+3)."Debt2nd"}, $strEMailContent);
	}
	
	$PropertyaCaveat = preg_split("[|]",$arrayres['app_PropertyCaveat_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"Property".($n+3)."Caveat"}=$PropertyaCaveat[$n];	
		$pattern = "Property".($n+3)."Caveat";
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"Property".($n+3)."Caveat"}, $strEMailContent);
	}

	$PropertyaType = preg_split("[|]",$arrayres['app_PropertyType_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"Property".($n+3)."Type"}=$PropertyaType[$n];	
		$pattern = "Property".($n+3)."Type";
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"Property".($n+3)."Type"}, $strEMailContent);
	}
	
	$PropertyaTypeOther = preg_split("[|]",$arrayres['app_PropertyTypeOther_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"Property".($n+3)."TypeOther"}=$PropertyaTypeOther[$n];	
		$pattern = "Property".($n+3)."TypeOther";
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"Property".($n+3)."TypeOther"}, $strEMailContent);
	}
	
	$PropertyaDescription = preg_split("[|]",$arrayres['app_PropertyDescription_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"Property".($n+3)."Description"}=$PropertyaCaveat[$n];	
		$pattern = "Property".($n+3)."Description";
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"Property".($n+3)."Description"}, $strEMailContent);
	}
	
	$PropertyaBedrooms = preg_split("[|]",$arrayres['app_PropertyBedrooms_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"Property".($n+3)."Bedrooms"}=$PropertyaBedrooms[$n];	
		$pattern = "Property".($n+3)."Bedrooms";
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"Property".($n+3)."Bedrooms"}, $strEMailContent);
	}
	
	$PropertyaBathrooms = preg_split("[|]",$arrayres['app_PropertyBathrooms_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"Property".($n+3)."Bathrooms"}=$PropertyaBathrooms[$n];	
		$pattern = "Property".($n+3)."Bathrooms";
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"Property".($n+3)."Bathrooms"}, $strEMailContent);
	}
	
	$PropertyaLandSize = preg_split("[|]",$arrayres['app_PropertyLandSize_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"Property".($n+3)."LandSize"}=$PropertyaLandSize[$n];	
		$pattern = "Property".($n+3)."LandSize";
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"Property".($n+3)."LandSize"}, $strEMailContent);
	}
	
	$morarra = preg_split("[|]",$arrayres['app_morarr_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"morarr".($n+3)}=$morarra[$n];	
		$pattern = "morarr".($n+3);
		if(${"morarr".($n+3)}=="yes")
			${"morarr".($n+3)}= 'yes <img src="../Pics/stars_grey.png" width="20" height="18" border="0">';
		
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"morarr".($n+3)}, $strEMailContent);
	}
	
	$monarra = preg_split("[|]",$arrayres['app_monarr_all'],$pptynum);
	for ($n=0;$n<$pptynum;$n++){
		${"monarr".($n+3)}=$monarra[$n];	
		$pattern = "monarr".($n+3);
		$strEMailContent = str_ireplace("{\$".$pattern."}", ${"monarr".($n+3)}, $strEMailContent);
	}
// end mutiple properties	

//calculate LVR
//$arrayres["app_HomeAmountOwing"] = parseInt($arrayres["app_HomeAmountOwing"].replace(/\,/g,""));
if ($arrayres["app_HomeValue"]!=""&&$arrayres["app_HomeValue"]!=0){
	$LVRp1 = intval((str_ireplace(",","",$arrayres["app_HomeAmountOwing"]))*100/ (str_ireplace(",","",$arrayres["app_HomeValue"])) )."%";
}
else
	$LVRp1="0%";

$strEMailContent = str_ireplace("{\$LVRp1}", $LVRp1, $strEMailContent);

if ($arrayres["app_InvestmentValue"]!=""&&$arrayres["app_InvestmentValue"]!=0){
		$LVRp2 = intval((str_ireplace(",","",$arrayres["app_InvestmentAmountOwing"]))*100/ (str_ireplace(",","",$arrayres["app_InvestmentValue"])) )."%";
	}
	else
		$LVRp2="0%";	
	
	$strEMailContent = str_ireplace("{\$LVRp2}", $LVRp2, $strEMailContent);

$pamount = $arrayres['app_AoP'];

if ($pamount>2){
	for ($i=3;$i<=$pamount;$i++){	
		if (${"InvestmentValue".$i}!=""&&${"InvestmentValue".$i}!=0){
			${"LVRp".$i} = intval((str_ireplace(",","",${"InvestmentAmountOwing".$i}))*100/ (str_ireplace(",","",${"InvestmentValue".$i})) )."%";
		}
		else
			${"LVRp".$i}="0%";	
		
		
		$strEMailContent = str_ireplace("{\$LVRp".$i."}", ${"LVRp".$i}, $strEMailContent);
	}
}
//calculate the amount of asset 
$asset = $arrayres['app_ApplyWithSomeoneWhoOwns'];
$vnum = 0;
$pnum = 1;
if ($arrayres['app_AoP']!="0")
	$pnum = $arrayres['app_AoP'];
if ($arrayres['app_Vehicle2Value']!="")
		$vnum=2;
	else
		$vnum=1;
if ($asset=="Motor Vehicle(s)")	{
	$asset = $vnum." Motor Vehicle(s)";
}

if ($asset=="Real Estate Property(s)")	{
	$asset = $pnum." Real Estate Property(s)";
}

if ($asset=="Motor Vehicle(s) and Real Estate Property(s)")	{
	$asset =$vnum." Motor Vehicle(s) and ".$pnum." Real Estate Property(s)";
}

$strEMailContent = str_ireplace("{\$Asset}", $asset, $strEMailContent);

$preapp_loanamount="";
$preapp_purpose="";
$preapp_own="";
$preapp_chistory="";
$preapp_wkincome="";
$preapp_monumber="";
$preapp_email="";
$preapp_state="";
$preapp_vis="none";
$preapp_hints="";

$strsql1= "select * from preapp_info where (preapp_ipaddress='".$arrayres['app_ipaddress']."' and preapp_ipaddress!='') order by preapp_id desc";


$strsql2= "select * from preapp_info where (preapp_code='".$arrayres['app_preappcode']."')  order by preapp_id desc";


$rs1 = mysql_query($strsql2) or die("Query failed2");
$arrayres1 = mysql_fetch_assoc($rs1);
//echo "value:".$arrayres1[0]; 
if (count($arrayres1)>1){
	$preapp_view="";
	$strEMailContent = str_ireplace("{\$preapp_name}", $arrayres1['preapp_name'], $strEMailContent);
	$strEMailContent = str_ireplace("{\$preapp_loamount}", $arrayres1['preapp_loamount'], $strEMailContent);
	$strEMailContent = str_ireplace("{\$preapp_purpose}", $arrayres1['preapp_purpose'], $strEMailContent);
	$strEMailContent = str_ireplace("{\$preapp_own}", $arrayres1['preapp_own'], $strEMailContent);
	$strEMailContent = str_ireplace("{\$preapp_chistory}", $arrayres1['preapp_chistory'], $strEMailContent);
	$strEMailContent = str_ireplace("{\$preapp_wkincome}", $arrayres1['preapp_wkincome'], $strEMailContent);
	$strEMailContent = str_ireplace("{\$preapp_monumber}", $arrayres1['preapp_monumber'], $strEMailContent);
	$strEMailContent = str_ireplace("{\$preapp_email}", $arrayres1['preapp_email'], $strEMailContent);$strEMailContent = str_ireplace("{\$preapp_state}", $arrayres1['preapp_state'], $strEMailContent);

$strEMailContent = str_ireplace("{\$preapp_date}", $arrayres1['preapp_date'], $strEMailContent);
$strEMailContent = str_ireplace("{\$preapp_time}", $arrayres1['preapp_time'], $strEMailContent);
$strEMailContent = str_ireplace("{\$preapp_sendfrom}", $arrayres1['preapp_sendfrom'], $strEMailContent);
$strEMailContent = str_ireplace("{\$preapp_browser}", $arrayres1['preapp_browser'], $strEMailContent);
$strEMailContent = str_ireplace("{\$preapp_ipaddress}", $arrayres1['preapp_ipaddress'], $strEMailContent);
$strEMailContent = str_ireplace("{\$preapp_code}", $arrayres1['preapp_code'], $strEMailContent);

$result="";

switch ($arrayres1['preapp_result']){
	case 1: $result="ap1.htm"; break;
	case 2: $result="ap2.htm"; break;
	case 3: $result="apjoin.htm"; break;
	case 4: $result="ap3.htm"; break;	
}

$strEMailContent = str_ireplace("{\$preapp_result}", $result, $strEMailContent);


}
else{
	$preapp_view="none";
	$preapp_hints="Can not trace Preapproval Form.";
}
$strEMailContent = str_ireplace("{\$preapp_view}", $preapp_view, $strEMailContent);
$strEMailContent = str_ireplace("{\$preapp_hints}", $preapp_hints, $strEMailContent);





//usb data retrieve
//$usbSql= "select * from usb_info where usb_appid=".$arrayres['app_id'];
$usbSql= "select * from usb_info where usb_appid=".$arrayres['comesfromId'];
$usbResult = mysql_query($usbSql);
if(!$usbResult) echo "usb Query failed";
$row = mysql_fetch_assoc($usbResult);
$strEMailContent = str_ireplace("{\$ref1name}", $row['usb_ref1name'], $strEMailContent);
$strEMailContent = str_ireplace("{\$ref1contact}", $row['usb_ref1contact'], $strEMailContent);
$strEMailContent = str_ireplace("{\$ref2name}", $row['usb_ref2name'], $strEMailContent);
$strEMailContent = str_ireplace("{\$ref2contact}", $row['usb_ref2contact'], $strEMailContent);
$strEMailContent = str_ireplace("{\$item1}", $row['usb_item1'], $strEMailContent);
$strEMailContent = str_ireplace("{\$item2}", $row['usb_item2'], $strEMailContent);
$strEMailContent = str_ireplace("{\$item3}", $row['usb_item3'], $strEMailContent);
$strEMailContent = str_ireplace("{\$item4}", $row['usb_item4'], $strEMailContent);
$strEMailContent = str_ireplace("{\$value1}", $row['usb_value1'], $strEMailContent);
$strEMailContent = str_ireplace("{\$value2}", $row['usb_value2'], $strEMailContent);
$strEMailContent = str_ireplace("{\$value3}", $row['usb_value3'], $strEMailContent);
$strEMailContent = str_ireplace("{\$value4}", $row['usb_value4'], $strEMailContent);
$strEMailContent = str_ireplace("{\$guarantor}", $row['usb_guarantor'], $strEMailContent);


























	
	// Now remove all the remaning sections (if any)
	$strEMailContent = preg_replace('/{\$(.*?)}/', "", $strEMailContent);

echo $strEMailContent;


$strsql = "update app_info set app_damount=app_damount+1 where app_id =".$id; 
//echo $strsql;
mysql_query($strsql) or die("Query failed2");


//include("../database/db_disconn.inc");
?>

</div>
</body>
</html>